#! /usr/bin/env python

#Files I Created:
import Buttons
import Decks
import DrawBackgrounds
import Munchkin
import PlayerHands
import RaceCard
import RightBar
import ParticleEngine

#Files created by others:
import inputbox

#Other Files:
import os, sys
import math
import pygame
from pygame.locals import *

''' Munchin is an educational project only created to help learn Python and
    PyGame as well as basic programming concepts.  It was start April 09, 2011
    by James Pollard (Pollaj145161@Hotmail.com).  It is not meant for sale or
    for distribution.
'''
''' Much credit goes to Max Messerich who wrote Zombiez VS VerbrecherZ.
    I struggled learning Python for a long time and could never find a good
    tutorial for PyGame, but then I came upon his PyGame game and was able
    to read and learn from his code.  The layout had structure of my code is
    based upon his.  Thanks Max.  His project can be found here:
    http://code.google.com/p/zombiez-vs-criminalz/downloads/list
    and over at the PyGame site here:
    http://www.pygame.org/project-ZombieZ+VS+CriminalZ-1799-.html
'''
''' Credit also goes to Timothy Downs for creating inputbox.
    http://www.pygame.org/pcr/inputbox/index.php
'''
''' Audio Credit:
    http://www.lynnemusic.com/midi.html is where I got:
    bjorn__lynne-_medieval_banquet.mid
    bjorn__lynne-_witchwood_prologue.mid

    http://www.freesound.org/forum/index.php is where I got many sound effects
    Author = BristolStories, Audio Clip = 46136__BristolStories__window_thump.wav
    Author = JustinBW, Audio Clip = 80921__JustinBW__buttonchime02up.wav
    Author = Stickinthemud, Audio Clip =
    Author = HerbertBoland, Audio Clip = DoorCreak.wav

    Image Credits:
    Tile used is from site: (http://www.allthingsmini.com/patterns/tile/
    medieval_tile_patterns.html)
    Mouse pointer used is from site: (http://www.xwpshrine.com/iconscursors.htm)
    Player 1 - 6 turn images are from flamingtext.com
    Settings: font=cooper, size=70
    Door image during knocking down the door is from here:
    http://jeffreyjene.com/games/resources/sprites/spritesheets.htm
'''

# Initialize pygame
pygame.init ()

# Setup display
screen = pygame.display.set_mode ((1280,1024))
pygame.display.set_caption('Munchkin')

# Load Sprite Groups
backgrounds    = pygame.sprite.Group ()
buttons        = pygame.sprite.Group ()
mouse_sparkles = pygame.sprite.Group ()
sparkles       = pygame.sprite.Group ()

# Program will start at the start menu
run    = True
reset  = True
clock  = pygame.time.Clock ()

# Setting up the mouse
#pygame.mouse.set_cursor(size, hotspot, xormasks, andmasks)
pygame.mouse.set_cursor((8,8), (0,0), (0,0,0,0,0,0,0,0), (0,0,0,0,0,0,0,0))
cursor_picture = pygame.image.load('./data/images/Sword.png').convert_alpha()


# Top Level Functions -- in alphabetical order
def BeginningGamePlayerSetup (p_four, p_five, p_six):
    global num_players
    for r in range(4):
        DrawDoorCard(1)
        DrawDoorCard(1)
        DrawTreasureCard(1)
        DrawDoorCard(2)
        DrawTreasureCard(2)
        DrawDoorCard(3)
        DrawTreasureCard(3)

        if p_four != None:
            DrawDoorCard(4)
            DrawTreasureCard(4)
        if p_five != None:
            DrawDoorCard(5)
            DrawTreasureCard(5)
        if p_six != None:
            DrawDoorCard(6)
            DrawTreasureCard(6)

def DrawDoorCard (player):
    global p_one_hand, p_two_hand, p_three_hand, p_four_hand, p_five_hand, p_six_hand
    global door_deck

    # Draw door cards
    temp = door_deck.DrawCard()

    # If none, is there any cards that can be shuffled in from discard?
    if temp == None:
        ShuffleDoorDiscard ()
        # Can we draw a card now?
        temp = door_deck.DrawCard()

    if temp != None:
        if player == 1:
            p_one_hand.AddCard (temp)
        elif player == 2:
            p_two_hand.AddCard (temp)
        elif player == 3:
           p_three_hand.AddCard (temp)
        elif player == 4:
           p_four_hand.AddCard (temp)
        elif player == 5:
           p_five_hand.AddCard (temp)
        elif player == 6:
           p_six_hand.AddCard (temp)

def DrawSparkles (x1,x2,y1,y2):
    # This draws silver sparkles over the card that is currently highlighted
    # by the mouse
    time = pygame.time.get_ticks()
    sparkles.add (ParticleEngine.Sparkles(x1,x2,y1,y2, time))

def DrawTreasureCard (player):
    global p_one_hand, p_two_hand, p_three_hand, p_four_hand, p_five_hand, p_six_hand
    global treasure_deck

    # Draw treasure cards
    temp = treasure_deck.DrawCard()

    # If none, is there any cards that can be shuffled in from discard?
    if temp == None:
        ShuffleTreasureDiscard ()
        # Can we draw a card now?
        temp = treasure_deck.DrawCard()

    if temp != None:
        if player == 1:
            p_one_hand.AddCard (temp)
        elif player == 2:
            p_two_hand.AddCard (temp)
        elif player == 3:
            p_three_hand.AddCard (temp)
        elif player == 4:
            p_four_hand.AddCard (temp)
        elif player == 5:
            p_five_hand.AddCard (temp)
        elif player == 6:
            p_six_hand.AddCard (temp)

def Exit ():
    pygame.quit()
    sys.exit()

def MouseSparkles (x,y):
    # This draws red sparkles where the mouse is
    time = pygame.time.get_ticks()
    mouse_sparkles.add (ParticleEngine.SparklesMouse(x, y, time))

def SetUpDecks ():
    SetUpRaceCards()

def SetUpRaceCards (door_deck, master_container):
    # cards:
    # 3 halflings
    # 3 elves
    # 3 dwarves
    # 2 supermunchkins
    door_deck.AddCard (RaceCard.Race('Dwarf1', master_container))
    door_deck.AddCard (RaceCard.Race('Dwarf2', master_container))
    door_deck.AddCard (RaceCard.Race('Dwarf3', master_container))
    door_deck.AddCard (RaceCard.Race('Elf1', master_container))
    door_deck.AddCard (RaceCard.Race('Elf2', master_container))
    door_deck.AddCard (RaceCard.Race('Elf3', master_container))
    door_deck.AddCard (RaceCard.Race('Halfling1', master_container))
    door_deck.AddCard (RaceCard.Race('Halfling2', master_container))
    door_deck.AddCard (RaceCard.Race('Halfling3', master_container))
    door_deck.AddCard (RaceCard.Race('Halfbreed1', master_container))
    door_deck.AddCard (RaceCard.Race('Halfbreed2', master_container))

def SetMenu (number):
    global menu
    menu = number

def ShuffleDoorDiscard ():
    global door_discard_deck, door_deck
    # Take all cards from the door discard deck and put them in door draw deck.
    while door_discard_deck.GetLength() > 0:
        door_deck.AddCard(door_discard_deck.deck.pop())

def ShuffleTreasureDiscard ():
    global treasure_discard_deck, treasure_deck
    # Take all cards from the treasure discard deck and put them in door draw deck.
    while treasure_discard_deck.GetLength() > 0:
        treasure_deck.AddCard(treasure_discard_deck.deck.pop())

def StartMusic (filename):
    pygame.mixer.music.fadeout(200)
    filepath = os.path.join ('data/audio/', filename)
    pygame.mixer.music.load (filepath)
    pygame.mixer.music.play (-1)
    pygame.mixer.music.set_volume (0.2)

def UpdatePlayerTurn (master_container, turn):
    master_container[4].player_turn = turn
    master_container[7].player_turn = turn
    master_container[10].player_turn = turn

    if master_container[13] != None:
        master_container[13].player_turn = turn
    if master_container[16] != None:
        master_container[16].player_turn = turn
    if master_container[19] != None:
        master_container[19].player_turn = turn

def ZoomInOnCard (card):
    zoomed_card = card






# Main Game Loop
while run:
    clock.tick(30)                  # 30 FPS
    x,y = pygame.mouse.get_pos ()   #set x and y to mouse_x and mouse_y
    mouse = False

    for event in pygame.event.get ():
        if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN
                                    and event.key == pygame.K_ESCAPE):
            Exit ()

        if event.type == pygame.KEYDOWN and event.key == pygame.K_r:
            # User presses 'r' - reset the game
            reset = True

        if event.type == pygame.KEYDOWN and event.key == pygame.K_s:
            # Quick startup used for testing
            menu = 98

        if event.type == MOUSEBUTTONDOWN: # Is user clicking the mouse?
            mouse=True

        if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
            if game == 4:
                game = 5

    # RESET THE GAME
    if reset:
        # Clear all the groups to null and reset variables
        backgrounds.empty ()
        buttons.empty ()
        sparkles.empty ()
        mouse_sparkles.empty ()

        menu                = 1
        game                = 0
        num_players         = 0
        player_turn         = 1
        clock               = pygame.time.Clock ()
        right_bar           = RightBar.RightBar ()
        door_deck           = Decks.DoorDeck ()
        door_discard_deck   = Decks.DoorDiscardDeck ()
        treasure_deck       = Decks.TreasureDeck ()
        treasure_discard_deck = Decks.TreasureDiscardDeck ()
        reset               = False
        mouse               = False
        p_one_hand          = None
        p_two_hand          = None
        p_three_hand        = None
        p_four_hand         = None
        p_five_hand         = None
        p_six_hand          = None
        zoomed_card         = None
        player_list        = []
        visible_hand_cards  = []
        player_hands        = []

        # Creating the players
        p_one   = Munchkin.Munchkin(1)
        p_two   = Munchkin.Munchkin(2)
        p_three = Munchkin.Munchkin(3)
        p_four  = Munchkin.Munchkin(4)
        p_five  = Munchkin.Munchkin(5)
        p_six   = Munchkin.Munchkin(6)

        # Create the playfields
        p_one.player_playfield   = []
        p_two.player_playfield   = []
        p_three.player_playfield = []
        p_four.player_playfield  = []
        p_five.player_playfield  = []
        p_six.player_playfield   = []

        # Add the background
        backgrounds.add (DrawBackgrounds.BG('startmenu_img.png', 0, 0, False))

        # Add the start and quit buttons to opening screen
        buttons.add (
            Buttons.StartMenuButton('Start', SetMenu, 600, 390, 2),
            Buttons.StartMenuButton('Quit', Exit, 600, 510, False))

        # Add music to play
        StartMusic ('bjorn__lynne-_witchwood_prologue.mid')

        # Set up the master container list
        # This is used to help move cards from one container object to another.
        master_container = []
        master_container.append (door_deck)               # 0
        master_container.append (door_discard_deck)       # 1
        master_container.append (treasure_deck)           # 2
        master_container.append (treasure_discard_deck)   # 3
        master_container.append (p_one)                   # 4
        master_container.append (p_one_hand)              # 5
        master_container.append (p_one.player_playfield)  # 6
        master_container.append (p_two)                   # 7
        master_container.append (p_two_hand)              # 8
        master_container.append (p_two.player_playfield)  # 9
        master_container.append (p_three)                 # 10
        master_container.append (p_three_hand)            # 11
        master_container.append (p_three.player_playfield)# 12
        master_container.append (p_four)                  # 13
        master_container.append (p_four_hand)             # 14
        master_container.append (p_four.player_playfield) # 15
        master_container.append (p_five)                  # 16
        master_container.append (p_five_hand)             # 17
        master_container.append (p_five.player_playfield) # 18
        master_container.append (p_six)                   # 19
        master_container.append (p_six_hand)              # 20
        master_container.append (p_six.player_playfield)  # 21
        master_container.append (screen)                  # 22
        master_container.append (DrawSparkles)            # 23

    # START MENU
    # Menu is not a bool value
    # Instead, it is an int, so that I can go through various stages of game setup.
    # A = Wait for user to click start
    # B = Get Number of players
    # C = Get sex of each player

    elif menu > 0:
        if menu == 1:
            # Wait for button click from user. Then go to 2.
            pass
        elif menu == 2:
            # Remove the start/quit button and proceed to 3.
            buttons.empty ()
            menu = 3

        elif menu == 3:
            # Get number of players and go to 4
            num_players = inputbox.ask(screen, "Number of players (3-6)")
            try:
                num_players = int(num_players)
            except:
                num_players = 0
            menu = 4

        elif menu == 4:
            # If number is correct, go to 5; otherwise, go back.
            if 3 <= num_players <= 6:
                menu = 5 # proceed
            else:
                menu = 3 # go back and get a valid number

        elif menu == 5:
            # Get sex of player one
            player_sex = inputbox.ask (screen, "Player One Sex (m) or (f)")
            menu = 6

        elif menu == 6:
            # Validate sex of player one
            if player_sex == 'm' or player_sex == 'f':
                p_one.sex = player_sex
                p_one.player = 1
                menu = 7
            else:
                menu = 5

        elif menu == 7:
            # Get sex of player two
            player_sex = inputbox.ask (screen, "Player Two Sex (m) or (f)")
            menu = 8

        elif menu == 8:
            # Validate sex of player two
            if player_sex == 'm' or player_sex == 'f':
                p_two.sex = player_sex
                p_two.player = 2
                menu = 9
            else:
                menu = 7

        elif menu == 9:
            # Get sex of player three
            player_sex = inputbox.ask (screen, "Player Three Sex (m) or (f)")
            menu = 10

        elif menu == 10:
            # Validate sex of player three
            if player_sex == 'm' or player_sex == 'f':
                p_three.sex = player_sex
                p_three.player = 3

                # if there are 4 players, set up player 4.  else, skip to next part.
                if num_players > 3:
                    menu = 11
                else:
                    menu = 99
            else:
                menu = 9

        elif menu == 11:
            # Get sex of player four
            player_sex = inputbox.ask (screen, "Player Four Sex (m) or (f)")
            menu = 12

        elif menu == 12:
            # Validate sex of player four
            if player_sex == 'm' or player_sex == 'f':
                p_four.sex = player_sex
                p_four.player = 4

                # if there are 5 players, set up player 5.  else, skip to next part.
                if num_players > 4:
                    menu = 13
                else:
                    menu = 99
            else:
                menu = 11

        elif menu == 13:
            # Get sex of player five
            player_sex = inputbox.ask (screen, "Player Five Sex (m) or (f)")
            menu = 14

        elif menu == 14:
            # Validate sex of player five
            if player_sex == 'm' or player_sex == 'f':
                p_five.sex = player_sex
                p_five.player = 5

                # if there are 6 players, set up player 6.  else, skip to next part.
                if num_players > 5:
                    menu = 15
                else:
                    menu = 99
            else:
                menu = 13

        elif menu == 15:
            # Get sex of player six
            player_sex = inputbox.ask (screen, "Player Six Sex (m) or (f)")
            menu = 16

        elif menu == 16:
            # Validate sex of player six
            if player_sex == 'm' or player_sex == 'f':
                p_six.sex = player_sex
                p_six.player = 6

                # skip to next part. max number of players reached.
                menu = 99
            else:
                menu = 15

        elif menu == 98:
            # Shortcut to start the game with 3 players.
            menu = 99
            for b in buttons.sprites():
                b.kill()
            num_players = 6
            p_one.sex = 'm'
            p_one.player=1
            p_two.sex = 'f'
            p_two.player=2
            p_three.sex = 'm'
            p_three.player=3
            p_four.sex = 'f'
            p_four.player = 4
            p_five.sex = 'm'
            p_five.player = 5
            p_six.sex = 'f'
            p_six.player = 6

        # Done setting up characters. Start the game.
        elif menu == 99:
            menu = 0
            game = 1
            time_count = 0
            SetUpRaceCards (door_deck, master_container)
            backgrounds.empty ()

            # Play the next background music track
            StartMusic ('bjorn__lynne-_medieval_banquet.mid')

            # Setup the background
            wid = 1280 / 80
            hei = 1024 / 80
            for r in range (wid):
                for rr in range (hei + 1):
                    xx = 80 * r
                    yy = 80 * rr
                    backgrounds.add (DrawBackgrounds.BG('T_medieval_tile_brown02.gif', xx, yy, True))

            # Add each player to the players container, players draws the sprites
            player_list.append(p_one)
            player_list.append(p_two)
            player_list.append(p_three)
            if num_players > 3:
                player_list.append (p_four)
            else:
                p_four = None
                p_five = None
                p_six  = None
            if num_players > 4:
                player_list.append (p_five)
            else:
                p_five = None
                p_six  = None
            if num_players > 5:
                player_list.append (p_six)
            else:
                p_six  = None

            # Set up each players hand and pass master_container to the player objects for reference.
            p_one_hand = PlayerHands.Hands (1)
            master_container[5] = p_one_hand
            player_hands.append (p_one_hand)
            p_one.UpdateMasterContainer (master_container)
            p_two_hand = PlayerHands.Hands (2)
            master_container[8] = p_two_hand
            player_hands.append (p_two_hand)
            p_two.UpdateMasterContainer (master_container)
            p_three_hand = PlayerHands.Hands (3)
            master_container[11] = p_three_hand
            player_hands.append (p_three_hand)
            p_three.UpdateMasterContainer (master_container)
            if p_four != None:
                p_four_hand = PlayerHands.Hands (4)
                master_container[14] = p_four_hand
                player_hands.append (p_four_hand)
                p_four.UpdateMasterContainer (master_container)
            if p_five != None:
                p_five_hand = PlayerHands.Hands (5)
                master_container[17] = p_five_hand
                player_hands.append (p_five_hand)
                p_five.UpdateMasterContainer (master_container)
            if p_six != None:
                p_six_hand = PlayerHands.Hands (6)
                master_container[20] = p_six_hand
                player_hands.append (p_six_hand)
                p_six.UpdateMasterContainer (master_container)

            # Setting up master container for the decks now.
            door_deck.SetupMasterContainer(master_container)
            door_discard_deck.SetupMasterContainer(master_container)
            treasure_deck.SetupMasterContainer(master_container)
            treasure_discard_deck.SetupMasterContainer(master_container)
            # Setting up master container for the hands
            p_one_hand.SetupMasterContainer(master_container)
            p_two_hand.SetupMasterContainer(master_container)
            p_three_hand.SetupMasterContainer(master_container)
            if p_four != None:
                p_four_hand.SetupMasterContainer(master_container)
            if p_five != None:
                p_five_hand.SetupMasterContainer(master_container)
            if p_six != None:
                p_six_hand.SetupMasterContainer(master_container)

            BeginningGamePlayerSetup (p_four, p_five, p_six)

    # Below here is the final steps of the game loop. it takes care of all the drawing of stuff and updating

    #Draw background
    for b in backgrounds.sprites():
        b.Show(screen)

    #Draw character cards
    for p in player_list:
        p.Update (x, y, mouse)
        p.Show ()

    # Draw any buttons
    for b in buttons.sprites():
        b.Update(x,y,mouse)
        b.Show(screen)

    # Only display player cards, hands, etc while in the game
    if game > 0:

        # Draw players hands next to their munchkin card and update the cards in hands
        for count in player_hands:
            count.Update(x, y, mouse)

        # Right bar holds the door and treasure decks as well as the discard piles
        # update door deck with mouse data, and possibly retrieve a card
        right_bar.Update () # Draw bar as black
        screen.blit (right_bar.surface, right_bar.rect)

        # Add any visible cards in hand to visible_cards []
        if p_one_hand != None:
            if p_one_hand.clicked_on_deck:
                visible_hand_cards = p_one_hand.hand_list
            else:
               visible_hand_cards = []

        # Go through all visible cards and see if mouse is over them to be zoomed.
        for card in visible_hand_cards:
            card.Update (x, y, mouse)

        # draw door image to bar
        door_deck.Update(x, y, mouse)

        # draw door discard image to bar
        door_discard_deck.Update (x, y, mouse)

        # draw treasure image to bar
        treasure_deck.Update(x, y, mouse)

        # draw treasure discard image to bar
        treasure_discard_deck.Update (x, y, mouse)

    time = pygame.time.get_ticks()

    # Draw particle effects on cards.
    for s in sparkles.sprites():
        if time > s.time:
            s.kill
        else:
            s.update (screen)

    # Mouse leaves behind a trail of particles.
    MouseSparkles (x,y)

    for s in mouse_sparkles.sprites():
        if time > s.time:
            s.kill
        else:
            s.update (screen)

    # PLAYER ONE'S TURN
    if game == 1:
        # Update game with what turn it is - 1
        player_turn = 1
        game = 2
        UpdatePlayerTurn (master_container, player_turn)

    elif game == 2:
        # Player 1 kicks down the door
        print 'Player 1 kicks down the door.'
        door_deck.KnockDownTheDoor (1)

        # If it is a monster, skip next part
        game = 3

    elif game == 3:
        print ('First door card was not a monster card. You may now ' +
        'play a monster card or draw a second door card.')
        # If the first card was not a monster card, draw another card
        # or play a monster from hand
        print "Press Space when you are done with your turn."
        game = 4

    elif game == 4:
        # Just wait for the user to press space.
        pass

    elif game == 5:
        # Charity phase.  If player has more cards then is allowed, player needs
        # to discard some cards.
        p_one_hand.EndOfTurn()
        game = 6

    # PLAYER TWO'S TURN
    elif game == 6:
        player_turn = 2
        game = 7
        UpdatePlayerTurn (master_container, player_turn)

    elif game == 7:
        # Player 2 kicks down the door
        print 'Player 2 kicks down the door.'
        door_deck.KnockDownTheDoor (2)

        # If it is a monster, skip next part
        game = 8

    elif game == 8:
        print ('First door card was not a monster card. You may now ' +
        'play a monster card or draw a second door card.')
        # If the first card was not a monster card, draw another card
        # or play a monster from hand
        print "Press Space when you are done with your turn."
        game = 9

    elif game == 9:
        # Just wait for the user to press space.
        game = 10

    elif game == 10:
        # Charity phase.  If player has more cards then is allowed, player needs
        # to discard some cards.
        p_two_hand.EndOfTurn()
        game = 11

    # PLAYER THREE'S TURN
    elif game == 11:
        player_turn = 3
        game = 12
        UpdatePlayerTurn (master_container, player_turn)

    elif game == 12:
        # Player 3 kicks down the door
        print 'Player 3 kicks down the door.'
        door_deck.KnockDownTheDoor (3)

        # If it is a monster, skip next part
        game = 13

    elif game == 13:
        print ('First door card was not a monster card. You may now ' +
        'play a monster card or draw a second door card.')
        # If the first card was not a monster card, draw another card
        # or play a monster from hand
        print "Press Space when you are done with your turn."
        game = 14

    elif game == 14:
        # Just wait for the user to press space.
        game = 15

    elif game == 15:
        # Charity phase.  If player has more cards then is allowed, player needs
        # to discard some cards.
        p_three_hand.EndOfTurn()
        if p_four != None:
            game = 16
        else:
            game = 1

    # PLAYER FOUR'S TURN
    if game == 16:
        player_turn = 4
        game = 17
        UpdatePlayerTurn (master_container, player_turn)

    elif game == 17:
        # Player 4 kicks down the door
        print 'Player 4 kicks down the door.'
        door_deck.KnockDownTheDoor (4)

        # If it is a monster, skip next part
        game = 18

    elif game == 18:
        print ('First door card was not a monster card. You may now ' +
        'play a monster card or draw a second door card.')
        # If the first card was not a monster card, draw another card
        # or play a monster from hand
        print "Press Space when you are done with your turn."
        game = 19

    elif game == 19:
        # Just wait for the user to press space.
        game = 20

    elif game == 20:
        # Charity phase.  If player has more cards then is allowed, player needs
        # to discard some cards.
        p_four_hand.EndOfTurn()

        if p_five!=None:
            game = 21
        else:
            game = 1

    # PLAYER FIVE'S TURN
    if game == 21:
        player_turn = 5
        game = 22
        UpdatePlayerTurn (master_container, player_turn)

    elif game == 22:
        # Player 5 kicks down the door
        print 'Player 5 kicks down the door.'
        door_deck.KnockDownTheDoor (5)

        # If it is a monster, skip next part
        game = 23

    elif game == 23:
        print ('First door card was not a monster card. You may now ' +
        'play a monster card or draw a second door card.')
        # If the first card was not a monster card, draw another card
        # or play a monster from hand
        print "Press Space when you are done with your turn."
        game = 24

    elif game == 24:
        # Just wait for the user to press space.
        game = 25

    elif game == 25:
        # Charity phase.  If player has more cards then is allowed, player needs
        # to discard some cards.
        p_five_hand.EndOfTurn()

        if p_six != None:
            game = 26
        else:
            game = 1

# PLAYER SIX'S TURN
    if game == 26:
        player_turn = 6
        game = 27
        UpdatePlayerTurn (master_container, player_turn)

    elif game == 27:
        # Player 6 kicks down the door
        print 'Player 6 kicks down the door.'
        door_deck.KnockDownTheDoor (6)

        # If it is a monster, skip next part
        game = 28

    elif game == 28:
        print ('First door card was not a monster card. You may now ' +
        'play a monster card or draw a second door card.')
        # If the first card was not a monster card, draw another card
        # or play a monster from hand
        print "Press Space when you are done with your turn."
        game = 29

    elif game == 29:
        # Just wait for the user to press space.
        game = 30

    elif game == 30:
        # Charity phase.  If player has more cards then is allowed, player needs
        # to discard some cards.
        p_six_hand.EndOfTurn()
        game = 1

    screen.blit(cursor_picture, pygame.mouse.get_pos())
    pygame.display.flip()
